//
//  FMSQLiteDetailHeader.m
//  WeEsion
//
//  Created by reylen on 15/12/24.
//  Copyright © 2015年 fdauto. All rights reserved.
//

#import "FMSQLiteDetailHeader.h"
#import "UIColor-Extension.h"

@implementation FMSQLiteDetailHeader

- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *) titles
{
    self = [super initWithFrame:frame];
    if (self) {
        
        if (titles.count > 0) {
            UIColor* lightColor = [UIColor lineColor];
            UIColor* heightColor = [UIColor colorWithHex:@"#8fcdd2"];
            
            CGFloat width = [UIScreen mainScreen].bounds.size.width;
            CGFloat _item_width = titles.count * 80 < width ? width / titles.count : 80;
            
            int count = 0;
            for (NSString* title in titles) {
                
                UIColor* backColor = count%2 ? heightColor : lightColor;
                
                UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.tag = count;
                [button setFrame:CGRectMake(_item_width* count++, 0, _item_width, frame.size.height)];
                [button setTitle:title forState:UIControlStateNormal];
                [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [button setTitleColor:[UIColor barColor] forState:UIControlStateSelected];
                [button setBackgroundColor:backColor];
                button.titleLabel.font = [UIFont systemFontOfSize:12];
                button.titleLabel.numberOfLines = 2;
                button.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
                [button addTarget:self action:@selector(buttonClickAction:) forControlEvents:UIControlEventTouchUpInside];
                [self addSubview:button];
                
            }
            
            UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0, frame.size.height - 1, frame.size.width, 1)];
            line.backgroundColor = [UIColor whiteColor];
            [self addSubview:line];
        }
        

    }
    return self;
}

- (IBAction)buttonClickAction:(id)sender {
    
}

@end
